﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TS_XY_Train_Repaire.Locomotive.Plane
{
    public partial class Locomotive_Train_Gant_ChangeDay : DevExpress.XtraEditors.XtraForm
    {
        public string _LoadBMWID, _LoadBMWDID, _LoadStime, _LoadEtime, _LoadName = "";

        private void bt_Exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Locomotive_Train_Gant_ChangeDay_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }

        private void bt_Sure_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("update TS_TR_BU_Work_Main_Day set f_length=" + (Convert.ToDateTime(de_etime.Text)).Subtract(Convert.ToDateTime(de_stime.Text)).Days.ToString() + "+1,f_pstime='" + de_stime.Text + "',f_petime='" + de_etime.Text + "',f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate() where f_id=" + _LoadBMWDID);
            TS_Win_Class.MySqlCom("update TS_TR_BU_Work_Main_Day set f_length=" + (Convert.ToDateTime(de_etime.Text)).Subtract(Convert.ToDateTime(de_stime.Text)).Days.ToString() + "+1,f_pstime='" + de_stime.Text + "',f_petime='" + de_etime.Text + "',f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate() where f_id=" + _LoadBMWDID);
            TS_Win_Class.MySqlCom("insert into TS_TR_H_Work_Schedule_Change(f_bmwid,f_bmwdid,f_brief,f_workerid) values(" + _LoadBMWID+","+_LoadBMWDID+",'"+tb_Brief.Text+"'," + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId +")");
            TS_Win_Class.Auto_Scheduling_Day_Change(_LoadBMWID, _LoadBMWDID,Convert.ToDateTime(de_etime.Text));
                this.Close();
        }

        private void Locomotive_Train_Gant_ChangeDay_Load(object sender, EventArgs e)
        {
            this.Text = _LoadName;
            de_stime.Text = _LoadStime;
            de_etime.Text = _LoadEtime;
            string strSQL = "select row_number() over (order by f_id asc) as f_row,f_id,(select f_name from TS_TR_BU_Work_Main_Day where f_id=TS_TR_H_Work_Schedule_Change.f_bmwdid) as f_name,f_brief,(select f_name from TS_S_T_P_Stuff where f_id=TS_TR_H_Work_Schedule_Change.f_workerid)as f_workername,f_time from TS_TR_H_Work_Schedule_Change where f_del=0 and f_bmwid=" + _LoadBMWID;
            DataTable _dt = new DataTable();
            TS_Win_Class.FilledDataTable(strSQL,_dt);
            gc_Main.DataSource = _dt;
        }

        public Locomotive_Train_Gant_ChangeDay()
        {
            InitializeComponent();
        }
    }
}